package com.ruoyi.project.system.mynotice.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.mynotice.domain.MyNotice;
import com.ruoyi.project.system.mynotice.service.MyNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 公告类别控制层
 * @author LHF
 */
@Controller
@RequestMapping("/system/mynotice")
public class MyNoticeController extends BaseController {

    private String prefix = "system/mynotice";

    @Autowired
    private MyNoticeService myNoticeService;

    @GetMapping()
    public String notice() {
        return prefix + "/notice_class";
    }

    /**
     * 根据调价查询所有申请
     * @return
     */
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo noticeList(String noticeClass) {
        startPage();
        List<MyNotice> allMyNotice = myNoticeService.findAllMyNotice(noticeClass);
        return getDataTable(allMyNotice);
    }


    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(myNoticeService.deleteMyNoticeById(ids));
    }

    /**
     * 添加页面
     * @return
     */
    @GetMapping("/toAdd")
    public String toAdd(){
        return prefix+"/add";
    }

    /**
     * 添加公告
     * @param myNotice
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(MyNotice myNotice){
        return toAjax(myNoticeService.addMyNotice(myNotice));
    }

    /**
     * 修改申请
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/edit/{applyId}")
    public String edit(@PathVariable("applyId") Long id, ModelMap mmap) {
        mmap.put("myNotice", myNoticeService.selectMyNoticeById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存申请
     * @param myNotice
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MyNotice myNotice) {
        return toAjax(myNoticeService.updateMyNotice(myNotice));
    }


}